package com.jf3q.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jf3q.admin.service.EduBannerService;
import com.jf3q.common.domain.EduBanner;
import com.jf3q.common.mapper.EduBannerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.io.File;

/**
* @author Administrator
* @description 针对表【edu_banner(首页banner表)】的数据库操作Service实现
* @createDate 2024-05-28 15:05:00
*/
@Service
public class EduBannerServiceImpl extends ServiceImpl<EduBannerMapper, EduBanner>
    implements EduBannerService {

    @Autowired
    EduBannerMapper eduBannerMapper;

    @Override
    public Page<EduBanner> getPage(Integer pageNum, EduBanner eduBanner) {

        Page<EduBanner> page = new Page<>(pageNum,2);
        QueryWrapper<EduBanner> queryWrapper = new QueryWrapper<>();
        if (!ObjectUtils.isEmpty(eduBanner.getTitle())) {
            queryWrapper.like("title",eduBanner.getTitle());
        }
        Page<EduBanner> iPage = baseMapper.selectPage(page, queryWrapper);
        return iPage;
    }

    @Override
    public Boolean del(String id) {
        EduBanner eduBanner = eduBannerMapper.selectById(id);
        int i = eduBannerMapper.deleteById(id);
        if (i>0){
            return true;
        }
//        String resultInfo = null;
//        String imagePath = "images/";
//        File file = new File(imagePath+eduBanner.getImageUrl());
//        if (file.exists()){
//            if (file.delete()){
//                resultInfo = "1";
//                int i = eduBannerMapper.deleteById(id);
//                if (i>0){
//                    return true;
//                }
//            }else {
//                resultInfo = "0";
//            }
//        }else {
//            resultInfo = "文件不存在！";
//        }
        return false;
    }

}




